home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_105 / bison / gram.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  119 lines

  1. /* Data definitions for internal representation of bison's input,
  2.    copyright (C) 1984 Bob Corbett and Richard Stallman
  3.  
  4.    Permission is granted to anyone to make or distribute verbatim copies of this program
  5.    provided that the copyright notice and this permission notice are preserved;
  6.    and provided that the recipient is not asked to waive or limit his right to
  7.    redistribute copies as permitted by this permission notice;
  8.    and provided that anyone possessing an executable copy
  9.    is granted access to copy the source code, in machine-readable form,
  10.    in some reasonable manner.
  11.  
  12.    Permission is granted to distribute derived works or enhanced versions of
  13.    this program under the above conditions with the additional condition
  14.    that the entire derivative or enhanced work
  15.    must be covered by a permission notice identical to this one.
  16.  
  17.    Anything distributed as part of a package containing portions derived
  18.    from this program, which cannot in current practice perform its function usefully
  19.    in the absense of what was derived directly from this program,
  20.    is to be considered as forming, together with the latter,
  21.    a single work derived from this program,
  22.    which must be entirely covered by a permission notice identical to this one
  23.    in order for distribution of the package to be permitted.
  24.  
  25.  In other words, you are welcome to use, share and improve this program.
  26.  You are forbidden to forbid anyone else to use, share and improve
  27.  what you give them.   Help stamp out software-hoarding!  */
  28.  
  29. /* representation of the grammar rules:
  30.  
  31. ntokens is the number of tokens, and nvars is the number of variables (nonterminals).
  32. nsyms is the total number, ntokens + nvars.
  33.  
  34. Each symbol (either token or variable) receives a symbol number.
  35. Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are for variables.
  36. Symbol number zero is the end-of-input token.  This token is counted in ntokens.
  37.  
  38. The rules receive rule numbers 1 to nrules in the order they are written.
  39. Actions and guards are accessed via the rule number.
  40.  
  41. The rules themselves are described by three arrays: rrhs, rlhs and ritems.
  42. rlhs[r] is the symbol number of the left hand side of rule r.
  43. The right hand side is stored as symbol numbers in a portion of ritems.
  44. rrhs[r] contains the index in ritems of the beginning of the portion for rule r.
  45. The length of the portion is one greater
  46.  than the number of symbols in the rule's right hand side.
  47. The last element in the portion contains minus r, which
  48. identifies it as the end of a portion and says which rule it is for.
  49.  
  50. The portions of ritems come in order of increasing rule number and are
  51. followed by an element which is zero to mark the end.  nitems is the
  52. total length of ritems, not counting the final zero.  Each element of
  53. ritems is called an "item" and its index in ritems is an item number.
  54.  
  55. Item numbers are used in the finite state machine to represent
  56. places that parsing can get to.
  57.  
  58. Precedence levels are recorded in the vectors sprec and rprec.
  59. sprec records the precedence level of each symbol,
  60. rprec the precedence level of each rule.
  61.  
  62. Precedence levels are assigned in increasing order starting with 1
  63. so that numerically higher precedence values mean tighter binding
  64. as they ought to.  Zero as a symbol or rule's precedence means none is assigned.
  65.  
  66. Associativities are recorded similarly in rassoc and sassoc.  */
  67.  
  68.  
  69. #define    ISTOKEN(s)    ((s) < ntokens)
  70. #define    ISVAR(s)    ((s) >= ntokens)
  71.  
  72.  
  73. extern int nitems;
  74. extern int nrules;
  75. extern int nsyms;
  76. extern int ntokens;
  77. extern int nvars;
  78.  
  79. extern short *ritem;
  80. extern short *rlhs;
  81. extern short *rrhs;
  82. extern short *rprec;
  83. extern short *sprec;
  84. extern short *rassoc;
  85. extern short *sassoc;
  86.  
  87. extern int start_symbol;
  88.  
  89.  
  90. /* associativity values in elements of rassoc, sassoc.  */
  91.  
  92. #define RIGHT_ASSOC 1
  93. #define LEFT_ASSOC 2
  94. #define NON_ASSOC 3
  95.  
  96. /* token translation table:
  97. indexed by a token number as returned by the user's yylex routine,
  98. it yields the internal token number used by the parser and throughout bison.
  99. If translations is zero, the translation table is not used because
  100. the two kinds of token numbers are the same.  */
  101.  
  102. extern short *token_translations;
  103. extern int translations;
  104. extern int max_user_token_number;
  105.  
  106. /* semantic_parser is nonzero if the input file says to use the hairy parser
  107. that provides for semantic error recovery.  If it is zero, the yacc-compatible
  108. simplified parser is used.  */
  109.  
  110. extern int semantic_parser;
  111.  
  112. /* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
  113.  
  114. extern int pure_parser;
  115.  
  116. /* error_token_number is the token number of the error token.  */
  117.  
  118. extern int error_token_number;
  119.